package com.jn.erp.wechat.staff.api.controller;

import com.jn.erp.common.core.result.AjaxResult;
import com.jn.erp.security.entity.SysUser;
import com.jn.erp.security.mapper.SysUserMapper;
import com.jn.erp.web.api.common.entity.TLog;
import com.jn.erp.web.api.common.service.TLogService;
import com.jn.erp.wechat.common.api.controller.base.BaseWxAuthController;
import com.jn.erp.wechat.common.api.entity.dto.WxUserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * <pre>
 *
 * </pre>
 *
 * @author sunjiyong
 * @since 2024/11/5 13:57
 */
@RestController
@RequestMapping("/wx/log")
public class MpTLogController extends BaseWxAuthController {

    @Autowired
    private TLogService tLogService;

    @Autowired
    private SysUserMapper sysUserMapper;
    /**
     修改记录新增新建   /tLog/saveOrderUpdate
     */
    @PostMapping("/saveOrderUpdate")
    public AjaxResult saveOrderUpdate(@RequestBody TLog tLog){
        WxUserDto wxUser = getWxUser();
        //机构id
        tLog.setOrgId(wxUser.getOrgIdLong() );
        //当前登录人id
        tLog.setCreateUser(String.valueOf(wxUser.getUserId()) );
        tLog.setCreateDate(LocalDateTime.now());
        tLog.setIsDelete("0");
        tLog.setName(sysUserMapper.selectNickByUserId(new SysUser(getUserId(),Long.parseLong(loginDeptAuth()))).getName());
        tLog.setMobile(getLoginUser().getUser().getName());
        String code = tLogService.saveOrderUpdate(tLog);
        return AjaxResult.success(code);
    }
}
